package com.xlh.controller.course;

import com.xlh.common.Result;
import com.xlh.dto.course.TheoryChapterLeanTimeStatisticsDTO;
import com.xlh.param.course.TheoryChapterLeanTimeStatisticsParam;
import com.xlh.param.course.TheoryLeanTimeStatisticsParam;
import com.xlh.param.course.TheoryVideoStatisticsParam;
import com.xlh.pojo.course.TheoryLearnTimeStatistics;
import com.xlh.security.UserInfoHolder;
import com.xlh.service.courseTest.TheoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author chufangzheng
 */
@RestController
@Api(tags = "TheoryController", description = "理论课")
@RequestMapping("/course")
public class TheoryController {

    @Autowired
    private TheoryService theoryService;


    @ApiOperation("理论视频时长保存")
    @PutMapping("/chapter/statistics/theoryVideo")
    @PreAuthorize("@permissionValidator.student")
    public Result theoryVideo(@Valid TheoryVideoStatisticsParam theoryVideoStatisticsParam) {
        theoryService.saveTheoryVideoTime(theoryVideoStatisticsParam);
        return Result.success();
    }


    @ApiOperation("理论课程是否播放完成")
    @GetMapping("/chapter/statistics/theoryVideoIsFinal")
    @PreAuthorize("@permissionValidator.student")
    public Result theoryVideoIsFinal(@Valid TheoryVideoStatisticsParam theoryVideoStatisticsParam){
        return Result.success(theoryService.theoryVideoIsFinal(theoryVideoStatisticsParam));
    }

    @ApiOperation("理论课学习时长统计")
    @PutMapping("/chapter/statistics/theoryLearnTime")
    @PreAuthorize("@permissionValidator.student")
    public Result theoryLearnTime(@Valid TheoryLeanTimeStatisticsParam theoryLeanTimeStatisticsParam){
        theoryService.theoryLearnTime(theoryLeanTimeStatisticsParam);
        return Result.success();
    }

    @ApiOperation("章节统计理论课学习时长")
    @PostMapping("/chapter/statistics/chapterLearnTime")
    @PreAuthorize("@permissionValidator.teacher")
    public Result chapterLearnTime(@RequestBody @Valid TheoryChapterLeanTimeStatisticsParam theoryLeanTimeStatisticsParam){

        List<TheoryChapterLeanTimeStatisticsDTO> result = theoryService.chapterLearnTime(theoryLeanTimeStatisticsParam);
        return Result.success(result);
    }



}
